package ru.spbau.krasko.phonelock.main;

import ru.spbau.krasko.phonelock.utils.Constants;

import net.rim.device.api.system.DeviceInfo;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.component.GaugeField;

public class BatteryGauge extends GaugeField{
	public BatteryGauge() {
		GlobalTimerExecutor.scheduleAtFixedRate(new Runnable() {			
			public void run() {
				invalidate();
			}
		}, 60 * 1000);
	}

	 protected void paint (Graphics g) {
		int percent = DeviceInfo.getBatteryLevel();
		int l = percent * Constants.SCREEN_W / 100;
		int R = 200 - percent * 2;
		int G = percent * 2;
		g.setColor((R << 16) | (G << 8));		
        g.fillRect(0, 0, l, 4);
        g.setColor(0x0);
        g.fillRect(l, 0, Constants.SCREEN_W - l, 4); 
    }
	
	protected void layout(int width, int height) {
        super.layout(width, height);
        setExtent (width, 4);
    }
}
